package com.example.g5project.repository.repo;

import com.example.g5project.entity.Consultant;
import com.example.g5project.entity.frontEndObject.ConsultantIDwithConsultNumber;
import com.example.g5project.entity.frontEndObject.ConsultantIDwithMonthGrade;
import com.example.g5project.repository.dao.ConsultantDao;
import com.example.g5project.repository.dao.ConsultantIDwithConsultNumberDao;
import com.example.g5project.repository.dao.ConsultantIDwithMonthGradeDao;
import org.assertj.core.util.Preconditions;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Optional;

/**
 * @author Hu Zirui
 * @version 1.0.0
 * @ClassName ConsultantRepo.java
 * @Description TODO
 * @createTime 2022年03月25日 14:50:00
 */
@Component
@Transactional
public class ConsultantRepo extends Repo<Consultant, Integer> {
    private final ConsultantDao consultantDao;
    private final ConsultantIDwithConsultNumberDao consultantIDwithConsultNumberDao;
    private final ConsultantIDwithMonthGradeDao consultantIDwithMonthGradeDao;

    public ConsultantRepo(@Qualifier("consultantDao") JpaRepository<Consultant, Integer> dao, ConsultantDao consultantDao, ConsultantIDwithConsultNumberDao consultantIDwithConsultNumberDao, ConsultantIDwithMonthGradeDao consultantIDwithMonthGradeDao) {
        super(dao);
        this.consultantDao = consultantDao;
        this.consultantIDwithConsultNumberDao = consultantIDwithConsultNumberDao;
        this.consultantIDwithMonthGradeDao = consultantIDwithMonthGradeDao;
    }

    public Optional<Consultant> findByName(String name) {
        return consultantDao.findByName(name);
    }

    public Integer add(Consultant consultant) {
        Preconditions.checkNotNull(consultant, "未输入内容");
        save(consultant);
        return consultant.getConsultant_id();
    }

    public ArrayList<Consultant> findAll() {
        return (ArrayList<Consultant>) consultantDao.findAll();
    }

    public Integer getTodayConsultNumber(int consultant_id) {
        return consultantDao.getByTodayConsultNumber(consultant_id);
    }

    public String getTodayConsultTime(int consultant_id) {
        return consultantDao.getByTodayConsultTime(consultant_id);
    }

    public ArrayList<Consultant> getAllAliveConsultant() {
        return consultantDao.getAllAliveConsultant();
    }

    public Integer getAllConsultSessionNumber() {
        return consultantDao.getAllAliveSessionNumber();
    }

    public ArrayList<ConsultantIDwithConsultNumber> getFirstKrankConsultantByConsultNumber(int k, int month) {
        System.out.println(k + " " + month);
        return consultantIDwithConsultNumberDao.getConsultantByConsultNumber(k, month);
    }

    public ArrayList<ConsultantIDwithMonthGrade> getFirstKrankConsultantByMonthsGrade(int k, int month) {
        return consultantIDwithMonthGradeDao.getConsultantByGrade(k, month);
    }

    public void deleteByName(String name) {
        consultantDao.deleteByName(name);
    }

    public void addAliveSessionNumber(Integer id) {
        consultantDao.addAliveSessionNumber(id);
    }

    public void addTodaySessionNumber(Integer id) {
        consultantDao.addTodaySessionNumber(id);
    }

    public ArrayList<String> getScheduleByMonth(String name, String month) {
        return consultantDao.getScheduleByMonth(name, month);
    }

    public Integer getGradeByName(String name) {
        return consultantDao.getGradeByName(name);
    }

    public void setStatus(String name) {
        consultantDao.setStatus(name);
    }

    public void increAllConsultNumber(String name) {
        consultantDao.increAllConsultNumber(name);
    }

    public void incretodayConsultNumber(String name) {
        consultantDao.incretodayConsultNumber(name);
    }

    public void updatetodayHoldTimeByName(String name, String hold_time) {
        consultantDao.updatetodayHoldTimeByName(name, hold_time);
    }

    public void updateallHoldTimeByName(String name, String hold_time) {
        consultantDao.updateallHoldTimeByName(name, hold_time);
    }

    public void addAliveSessionNumberByName(String name) {
        consultantDao.addAliveSessionNumberByName(name);
    }

    public void minusAliveSessionNumberByName(String name) {
        consultantDao.minusAliveSessionNumberByName(name);
    }

    public void minusAliveSessionNumber(Integer id) {
        consultantDao.minusAliveSessionNumber(id);
    }

}
